package win.demonlegion.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import win.demonlegion.mapper.TestMapper;
import win.demonlegion.module.TestBean;
import win.demonlegion.service.inte.TestService;
import win.demonlegion.util.TimestampUtil;

@Service("testService")
@CacheConfig(cacheNames = "test")
public class TestServiceImpl implements TestService {
    private static final Logger logger = LoggerFactory.getLogger(TestServiceImpl.class);

    @Autowired
    private TestMapper testMapper;

    @Override
    public int add(TestBean testBean) {
        if (testBean.getTime() == null) testBean.setTime(TimestampUtil.getDatetime());
        return testMapper.add(testBean);
    }

    @Override
    @Cacheable
    public TestBean fetch(long id) {
        return testMapper.fetch(id);
    }
}
